package uestc.bitman.edxapp.mainui;

import uestc.bitman.edxapp.R;

import android.app.Activity;
import android.widget.Toast;

public abstract class PressAgainExitActivity extends Activity{
    
    private boolean mExit = false;

    private boolean mExitSwitch = true;

    public void onBackPressed() {
        if (mExitSwitch) {
            if (mExit) {
                super.onBackPressed();
            } else {
                Toast.makeText(this, getString(R.string.press_again_exit), Toast.LENGTH_SHORT)
                        .show();
                new Thread(new TickerThread()).start();
            }
        } else {
            handleBackPress();
            super.onBackPressed();
        }
    }

    public void enablePressAgainToExit(boolean b) {
        mExitSwitch = b;
    }

    class TickerThread implements Runnable {
        @Override
        public void run() {
            mExit = true;
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mExit = false;
        }
    }
    
    public abstract void handleBackPress();
}
